package thisuse;

/**
 * @Author Stringzhua
 * @Date 2024/2/29 19:05
 * description:定义person类,里面有name,age属性,并提供compareTo比较方法
 * 用于判断是否和另一个人相等,提供测试类TestPerson用于测试
 * 名字和年龄完全一样,就返回true,否则返回false
 */
public class TestPerson {
    public static void main(String[] args) {
        Person p1 = new Person("zhuazhua", 20);
        Person p2 = new Person("zhuazhua", 20);

        System.out.println("p1和p2比较的结果"+p1.compareTo(p2));
    }
}

class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //compareTo方法
    public boolean compareTo(Person p) {
//        if (this.name.equals(p.name) && this.age == p.age) {
//            return true;
//        } else return false;
        return this.name.equals(p.name) && this.age == p.age;
    }
}
